<?php
require_once ('Logger/Appender/Abstraction.php');
require_once DATADRIVER_DIR.'/DAO/Log.php';

define('LOG_TYPE_LOGIN',1);
define('LOG_TYPE_LOGOUT',2);
define('LOG_TYPE_CHANGEPASS',3);
define('LOG_TYPE_DEL_CORP',4);
define('LOG_TYPE_PUB_CORP',5);
define('LOG_TYPE_EDIT_CORP',6);
define('LOG_TYPE_AUDIT_CORP',7);

define('LOG_TYPE_DEL_JOB',8);
define('LOG_TYPE_PUB_JOB',9);
define('LOG_TYPE_EDIT_JOB',10);
define('LOG_TYPE_AUDIT_JOB',11);


define('LOG_TYPE_OPEN_FEE',12);
define('LOG_TYPE_EDIT_FEE',13);

class Logger_Appender_LogDB extends Logger_Appender_Abstraction
{
    
    protected function _append(Logger_Event $event) {
        
        $msg = $event->getMessage();
        $this->_bufferSize += strlen ( $msg );
        $this->_logBuffer [] = $msg;
        
        if ($this->_bufferSize >= $this->_options['buffer'])
            $this->_flush ();
    }
    protected function _flush() {
      
        $dao    =   new DAO_Log();
        $user   = Context::registry('user');
        $uid    =   $user->userID;
        foreach($this->_logBuffer as $log)
        {
            $msg = explode("|",$log);
            $data['user_id']         =    $uid;
            $data['log_time']       =   date('Y-m-d H:i:s',NOW_TIME);
            $data['type']           =   $msg[0];
            $data['content']        =   $msg[1];
            $data['ip']             =   $_SERVER['REMOTE_ADDR'];
        
            $dao->add($data);
        }
        
        $this->_bufferSize  =   0;
        $this->_logBuffer   =   array();
    }
    protected function _close()
    {
        
    }
    
}
?>